package com.appoint.web.controller.buss;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.appoint.buss.domain.EpiparaRnaSeq;
import com.appoint.buss.domain.vo.EpiparaRnaRnaSeqRespVO;
import com.appoint.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.appoint.common.annotation.Log;
import com.appoint.common.core.controller.BaseController;
import com.appoint.common.core.domain.AjaxResult;
import com.appoint.common.enums.BusinessType;
import com.appoint.buss.domain.EpiparaRnaInfo;
import com.appoint.buss.service.IEpiparaInfoService;
import com.appoint.common.utils.poi.ExcelUtil;
import com.appoint.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * epipara_infoController
 * rna 明细
 * @author appoint
 * @date 2023-01-10
 */
@RestController
@RequestMapping("/buss/epiparaInfo")
public class EpiparaInfoController extends BaseController
{
    @Autowired
    private IEpiparaInfoService epiparaInfoService;

    /**
     * 查询epipara_info列表
     */
    @PreAuthorize("@ss.hasPermi('buss:epiparaInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(EpiparaRnaInfo epiparaInfo)
    {
        startPage();
        List<EpiparaRnaInfo> list = epiparaInfoService.selectEpiparaInfoList(epiparaInfo);
        return getDataTable(list);
    }

    /**
     * 导出epipara_info列表
     */
    @PreAuthorize("@ss.hasPermi('buss:epiparaInfo:export')")
    @Log(title = "epipara_info", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EpiparaRnaInfo epiparaInfo)
    {
        List<EpiparaRnaInfo> list = epiparaInfoService.selectEpiparaInfoList(epiparaInfo);
        ExcelUtil<EpiparaRnaInfo> util = new ExcelUtil<EpiparaRnaInfo>(EpiparaRnaInfo.class);
        util.exportExcel(response, list, "epipara_info数据");
    }

    /**
     * 获取epipara_info详细信息
     */
    @PreAuthorize("@ss.hasPermi('buss:epiparaInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(epiparaInfoService.getById(id));
    }

    /**
     * 新增epipara_info
     */
    @PreAuthorize("@ss.hasPermi('buss:epiparaInfo:add')")
    @Log(title = "epipara_info", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EpiparaRnaInfo epiparaInfo)
    {
        epiparaInfoService.insertEpiparaInfo(epiparaInfo);
        return toAjax(true);
    }

    /**
     * 修改epipara_info
     */
    @PreAuthorize("@ss.hasPermi('buss:epiparaInfo:edit')")
    @Log(title = "epipara_info", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EpiparaRnaInfo epiparaInfo)
    {
        return toAjax(epiparaInfoService.updateEpiparaInfo(epiparaInfo));
    }

    /**
     * 删除epipara_info
     */
    @PreAuthorize("@ss.hasPermi('buss:epiparaInfo:remove')")
    @Log(title = "epipara_info", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(epiparaInfoService.deleteEpiparaInfoByIds(ids));
    }

    /**
     * 查询epipara_info列表
     */
    @Anonymous
    @GetMapping("/list2")
    public TableDataInfo list2(EpiparaRnaSeq epiparaInfo)
    {
        startPage();
        List<EpiparaRnaRnaSeqRespVO> list = epiparaInfoService.queryEpipara(epiparaInfo);
        return getDataTable(list);
    }

    /**
     * 导出epipara_info列表
     */
    @Anonymous
    @PostMapping("/list2Export")
    public void list2Export(HttpServletResponse response, EpiparaRnaSeq epiparaInfo)
    {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        List<EpiparaRnaRnaSeqRespVO> list = epiparaInfoService.queryEpipara(epiparaInfo);
        ExcelUtil<EpiparaRnaRnaSeqRespVO> util = new ExcelUtil<>(EpiparaRnaRnaSeqRespVO.class);
        util.exportExcel(response, list, sdf.format(new Date()));
    }


    @Log(title = "总表信息导入", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('buss:epiparaInfo:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<EpiparaRnaInfo> util = new ExcelUtil<>(EpiparaRnaInfo.class);
        List<EpiparaRnaInfo> list = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = epiparaInfoService.importUser(list, updateSupport, operName);
        return AjaxResult.success(message);
    }

    /**
     * 查询联想列表
     */
    @Anonymous
    @GetMapping("/list4")
    public AjaxResult list4(EpiparaRnaInfo info)
    {
        Map<String,Object> param = new HashMap<>();
        param.put("species",info.getSpecies());
        param.put("query",info.getIndex());
        String result = epiparaInfoService.list4(param);
        return AjaxResult.success(result);
    }

}
